const gulp = require("gulp");
// const htmlmin = require("gulp-htmlmin");
 const babel = require("gulp-babel");
// const uglify = require("gulp-uglify");
const scss = require("gulp-sass");
const connect = require("gulp-connect");

//定制任务html
gulp.task("html",function(){
    gulp.src("src/**/*.html")
    // .pipe(htmlmin({ collapseWhitespace: true }))
    .pipe(gulp.dest("dist"))
    .pipe(connect.reload());
})

//压缩js
gulp.task('js', () => {
    gulp.src('src/js/**/*.js')
         .pipe(babel({ // 转换
            presets: ['env']
        }))
        // .pipe(uglify()) // 压缩
       
        .pipe(gulp.dest('dist/js'))
        .pipe(connect.reload());
});


//webserve
gulp.task("connect",()=>{
    connect.server({root:"dist",livereload:true})
});

//scss
gulp.task("scss", function () {
    gulp.src("src/scss/**/*.scss")
    .pipe(scss())
    .pipe(gulp.dest("dist/css"))
    .pipe(connect.reload());
});

//复制lib
gulp.task("copy-lib",()=>{
    gulp.src("src/lib/**/*.*")
            .pipe(gulp.dest("dist/lib"))
});
//复制php
gulp.task("copy-php",()=>{
    gulp.src("src/php/**/*.*")
            .pipe(gulp.dest("dist/php"))
});
//复制images
gulp.task("copy-images",()=>{
    gulp.src("src/images/**/*.*")
            .pipe(gulp.dest("dist/images"))
});
//copy css
gulp.task("copy-css",()=>{
    gulp.src("src/scss/**/*.css")
            .pipe(gulp.dest("dist/css"))
});
gulp.task("copy-common",()=>{
    gulp.src("src/common/**/*.*")
            .pipe(gulp.dest("dist/common"))
});
gulp.task("copy",["copy-images","copy-php","copy-common","copy-css","copy-lib"]);

//监视任务
gulp.task("watch",()=>{
    gulp.watch("src/js/*.js",["js"]);
    gulp.watch("src/**/.html",["html"]);
    gulp.watch("src/scss/*.*",["scss"]);
  
});
gulp.task("default",["html","js","scss","copy","connect","watch"]);
